package com.example.framework.mqtt.core.model;

import net.dreamlu.iot.mqtt.codec.MqttQoS;

/**
 * <p>
 *  mqtt 消息模型
 * </p>
 *
 * @author sfjiang
 * @since 2024/11/26 17:37
 */
public class MqttModel<T> {

    /**
     * 主题
     */
    private String topic;

    /**
     * 消息体
     */
    private T data;

    /**
     * qos
     */
    private MqttQoS qos = MqttQoS.QOS0;

    /**
     * 是否保留消息
     */
    private boolean retain = false;

    public MqttModel(String topic) {
        this.topic = topic;
    }

    public MqttModel(String topic, T data) {
        this.topic = topic;
        this.data = data;
    }

    public MqttModel(String topic, T data, MqttQoS qos) {
        this.topic = topic;
        this.data = data;
        this.qos = qos;
    }

    public String getTopic() {
        return topic;
    }

    public MqttModel<T> setTopic(String topic) {
        this.topic = topic;
        return this;
    }

    public MqttQoS getQos() {
        return qos;
    }

    public void setQos(MqttQoS qos) {
        this.qos = qos;
    }

    public T getData() {
        return data;
    }

    public MqttModel<T> setData(T data) {
        this.data = data;
        return this;
    }

    public boolean isRetain() {
        return retain;
    }

    public MqttModel<T> setRetain(boolean retain) {
        this.retain = retain;
        return this;
    }
}
